package com.yzzrjy.controller.mainservlet.update;

import com.yzzrjy.Service.UserService;
import com.yzzrjy.util.ResponseUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "DeleteAlbumServlet", value = "/deleteAlbum")
public class DeleteAlbumServlet extends HttpServlet {
    private UserService userService = new UserService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String uid = request.getParameter("uid");
        String token = request.getParameter("token");
        String url = request.getParameter("url");
        if(uid == null || token == null || url == null){
            ResponseUtils.parameterError(response);
            return;
        }
        try {
            boolean b = userService.deleteAlbum(uid, url);
            if(b){
                ResponseUtils.success(response, null);
                return;
            }
        } catch (SQLException e) {
            System.out.println("删除相册操作失败:" + url);
        }
        ResponseUtils.otherError(response, "删除操作失败");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
